using System;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace CSW.Framework.UI.DevEx.Forms
{
    /// <summary>
    /// DXGetDateForm
    /// </summary>
    public sealed partial class DXGetDateForm : XtraForm
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="DXGetDateForm"/> class.
        /// </summary>
        public DXGetDateForm()
            : this("Enter Date", DateTime.Now.Date)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="DXGetDateForm"/> class.
        /// </summary>
        /// <param name="label">The label.</param>
        public DXGetDateForm(string label)
            : this(label, DateTime.Now.Date)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="DXGetDateForm"/> class.
        /// </summary>
        /// <param name="label">The label.</param>
        /// <param name="defaultDate">The default date.</param>
        public DXGetDateForm(string label, DateTime defaultDate)
        {
            InitializeComponent();

            layoutControlItem2.Text = label;
            dateEdit1.EditValue = defaultDate.Date;
        }

        private void cmdCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void cmdOK_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
            Close();
        }

        /// <summary>
        /// Gets the date.
        /// </summary>
        /// <value>The date.</value>
        public DateTime? Date
        {
            get 
            {
                if (DialogResult == DialogResult.OK)
                    return ((DateTime)dateEdit1.EditValue).Date;
                else
                    return null;
            }
        }
    }
}